package com.boot.main.controller;

import com.boot.main.entity.ScomAd;
import com.boot.main.service.IAdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1/api")
@Api(tags = "banner管理")
public class AdController {
    @Resource
    private IAdService adService;

    @RequestMapping(value="/ads", method = RequestMethod.GET)
    @ApiOperation(value="获取banner列表")
    public Object getAds(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("name") String name){
        return adService.getAds(page, limit, name);
    }

    @RequestMapping(value="/ad", method = RequestMethod.POST)
    @ApiOperation(value="新增banner")
    public Object saveAd(@RequestBody ScomAd ad){
        return adService.saveAd(ad);
    }

    @RequestMapping(value="/ad/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="修改banner")
    public Object updateAd(@RequestBody ScomAd ad){
        return adService.updateAd(ad);
    }

    @RequestMapping(value="/ad/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除banner")
    public Object deleteAd(@PathVariable Long id){
        return adService.deleteAd(id);
    }
}
